/**
 * 作者: lby
 * 日期: 2024-11-20 10:13:33
 * 备注: 用户子嗣教室表
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.Common.PBUserChildCls;
import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UserChildClsModel extends BaseModel implements Model {
	public static final String LISTKEY = "user_id.cls_id";
	public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
	public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
	public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

	protected long id; // id
	protected long userId; // 玩家id
	protected int clsId; // 教室id (1,2,3,4,5在代码中有枚举对应的坑位)
	protected int energy; // 当前活力
	protected long energyRecoverTime; // 活力上次回复时间
	protected int studySchedule; // 教学进度
	protected int career; // 职业
	protected int careerAddition; // 职业加成 (百分比值, 计算时 /100)
	protected int partner; // 父亲
	protected int partnerAddition; // 父亲加成
	protected int secretary; // 母亲
	protected int secretaryAddition; // 母亲加成
	protected byte quality; // 品质
	protected byte appearance; // 外观 (0表示长相随父亲，取partner字段去partner_main表找头（其他值就根据secretary去secretary_main表找头），身体根据career去child_career_appearance表找)
	protected byte characterId; // 性格
	protected byte isTwins; // 是否双胞胎 (1是0否)
	protected String sisterName = ""; // 兄弟姐妹名字 (是双胞胎有值，不是双胞胎没值)
	protected byte sex; // 性别 (1男0女)
	protected byte sisterSex; // 兄弟姐妹性别 (1男0女)
	protected String name = ""; // 名字
	protected int isStudy; // 是否有小孩在教室 (0-表示空教室)
	protected long addition; // 已经加了的城市收益
	protected long baseConsume; // 上课一次的基础消耗

	public void reset() {
	}

	protected String getKey() {
		return "UserChildCls." + userId + "." + clsId;
	}

	protected String getListKey() {
		return "UserChildCls." + userId;
	}

	protected String getListItemKey() {
		return clsId + "";
	}

	public void doCreate() {
		setTableId();
		insert();
	}

	public void setTableId() {
		putId(incrTableId("user_child_cls"));
	}

	public JsonObject insert() {
		return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	public void delete() {
		super.delete(getKey(), id, UPDATE_DB_TYPE, userId, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	/**
	 * 根据入库类型更新
	 */
	public JsonObject update() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, userId, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	/**
	 * 实时入队列
	 */
	public JsonObject updateQueueNow() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	public JsonObject getAllObj(){
		JsonObject obj = new JsonObject();
		obj.put("id", id); // id
		obj.put("userId", userId); // 玩家id
		obj.put("clsId", clsId); // 教室id (1,2,3,4,5在代码中有枚举对应的坑位)
		obj.put("energy", energy); // 当前活力
		obj.put("energyRecoverTime", energyRecoverTime); // 活力上次回复时间
		obj.put("studySchedule", studySchedule); // 教学进度
		obj.put("career", career); // 职业
		obj.put("careerAddition", careerAddition); // 职业加成 (百分比值, 计算时 /100)
		obj.put("partner", partner); // 父亲
		obj.put("partnerAddition", partnerAddition); // 父亲加成
		obj.put("secretary", secretary); // 母亲
		obj.put("secretaryAddition", secretaryAddition); // 母亲加成
		obj.put("quality", quality); // 品质
		obj.put("appearance", appearance); // 外观 (0表示长相随父亲，取partner字段去partner_main表找头（其他值就根据secretary去secretary_main表找头），身体根据career去child_career_appearance表找)
		obj.put("characterId", characterId); // 性格
		obj.put("isTwins", isTwins); // 是否双胞胎 (1是0否)
		obj.put("sisterName", sisterName); // 兄弟姐妹名字 (是双胞胎有值，不是双胞胎没值)
		obj.put("sex", sex); // 性别 (1男0女)
		obj.put("sisterSex", sisterSex); // 兄弟姐妹性别 (1男0女)
		obj.put("name", name); // 名字
		obj.put("isStudy", isStudy); // 是否有小孩在教室 (0-表示空教室)
		obj.put("addition", addition); // 已经加了的城市收益
		obj.put("baseConsume", baseConsume); // 上课一次的基础消耗
		return obj;
	}

	public PBUserChildCls.Builder takeInitBuilder() {
		PBUserChildCls.Builder sb = PBUserChildCls.newBuilder();
		if (clsId != 0) {
			sb.setClsId(clsId);
		}
		if (energy != 0) {
			sb.setEnergy(energy);
		}
		if (energyRecoverTime != 0) {
			sb.setEnergyRecoverTime(energyRecoverTime);
		}
		if (studySchedule != 0) {
			sb.setStudySchedule(studySchedule);
		}
		if (career != 0) {
			sb.setCareer(career);
		}
		if (careerAddition != 0) {
			sb.setCareerAddition(careerAddition);
		}
		if (partner != 0) {
			sb.setPartner(partner);
		}
		if (partnerAddition != 0) {
			sb.setPartnerAddition(partnerAddition);
		}
		if (secretary != 0) {
			sb.setSecretary(secretary);
		}
		if (secretaryAddition != 0) {
			sb.setSecretaryAddition(secretaryAddition);
		}
		if (quality != 0) {
			sb.setQuality(quality);
		}
		if (appearance != 0) {
			sb.setAppearance(appearance);
		}
		if (characterId != 0) {
			sb.setCharacterId(characterId);
		}
		if (isTwins != 0) {
			sb.setIsTwins(isTwins);
		}
		if (!sisterName.isEmpty()) {
			sb.setSisterName(sisterName);
		}
		if (sex != 0) {
			sb.setSex(sex);
		}
		if (sisterSex != 0) {
			sb.setSisterSex(sisterSex);
		}
		if (!name.isEmpty()) {
			sb.setName(name);
		}
		if (isStudy != 0) {
			sb.setIsStudy(isStudy);
		}
		if (addition != 0) {
			sb.setAddition(addition);
		}
		if (baseConsume != 0) {
			sb.setBaseConsume(baseConsume);
		}
		return sb;
	}

	public PBUserChildCls.Builder takeBuilder() {
		if (updateObj == null || updateObj.isEmpty()) {
			return takeInitBuilder();
		}
		PBUserChildCls.Builder sb = PBUserChildCls.newBuilder();
		if (isFieldUpdate("clsId")) {
			sb.setClsId(clsId);
		}
		if (isFieldUpdate("energy")) {
			sb.setEnergy(energy);
		}
		if (isFieldUpdate("energyRecoverTime")) {
			sb.setEnergyRecoverTime(energyRecoverTime);
		}
		if (isFieldUpdate("studySchedule")) {
			sb.setStudySchedule(studySchedule);
		}
		if (isFieldUpdate("career")) {
			sb.setCareer(career);
		}
		if (isFieldUpdate("careerAddition")) {
			sb.setCareerAddition(careerAddition);
		}
		if (isFieldUpdate("partner")) {
			sb.setPartner(partner);
		}
		if (isFieldUpdate("partnerAddition")) {
			sb.setPartnerAddition(partnerAddition);
		}
		if (isFieldUpdate("secretary")) {
			sb.setSecretary(secretary);
		}
		if (isFieldUpdate("secretaryAddition")) {
			sb.setSecretaryAddition(secretaryAddition);
		}
		if (isFieldUpdate("quality")) {
			sb.setQuality(quality);
		}
		if (isFieldUpdate("appearance")) {
			sb.setAppearance(appearance);
		}
		if (isFieldUpdate("characterId")) {
			sb.setCharacterId(characterId);
		}
		if (isFieldUpdate("isTwins")) {
			sb.setIsTwins(isTwins);
		}
		if (isFieldUpdate("sisterName")) {
			sb.setSisterName(sisterName);
		}
		if (isFieldUpdate("sex")) {
			sb.setSex(sex);
		}
		if (isFieldUpdate("sisterSex")) {
			sb.setSisterSex(sisterSex);
		}
		if (isFieldUpdate("name")) {
			sb.setName(name);
		}
		if (isFieldUpdate("isStudy")) {
			sb.setIsStudy(isStudy);
		}
		if (isFieldUpdate("addition")) {
			sb.setAddition(addition);
		}
		if (isFieldUpdate("baseConsume")) {
			sb.setBaseConsume(baseConsume);
		}
		return sb;
	}

	public long getId() {
		return id;
	}

	public void putId(long id) {
		if (this.id != id) {
			this.id = id;
			updateRedisHashField(getKey(), "id", this.id);
		}
	}

	public void addId(long value) {
		this.id += value;
		updateRedisHashField(getKey(), "id", this.id);
	}

	public long getUserId() {
		return userId;
	}

	public void putUserId(long userId) {
		if (this.userId != userId) {
			this.userId = userId;
			updateRedisHashField(getKey(), "userId", this.userId);
		}
	}

	public void addUserId(long value) {
		this.userId += value;
		updateRedisHashField(getKey(), "userId", this.userId);
	}

	public int getClsId() {
		return clsId;
	}

	public void putClsId(int clsId) {
		if (this.clsId != clsId) {
			this.clsId = clsId;
			updateRedisHashField(getKey(), "clsId", this.clsId);
		}
	}

	public void addClsId(int value) {
		this.clsId += value;
		updateRedisHashField(getKey(), "clsId", this.clsId);
	}

	public int getEnergy() {
		return energy;
	}

	public void putEnergy(int energy) {
		if (this.energy != energy) {
			this.energy = energy;
			updateRedisHashField(getKey(), "energy", this.energy);
		}
	}

	public void addEnergy(int value) {
		this.energy += value;
		updateRedisHashField(getKey(), "energy", this.energy);
	}

	public long getEnergyRecoverTime() {
		return energyRecoverTime;
	}

	public void putEnergyRecoverTime(long energyRecoverTime) {
		if (this.energyRecoverTime != energyRecoverTime) {
			this.energyRecoverTime = energyRecoverTime;
			updateRedisHashField(getKey(), "energyRecoverTime", this.energyRecoverTime);
		}
	}

	public void addEnergyRecoverTime(long value) {
		this.energyRecoverTime += value;
		updateRedisHashField(getKey(), "energyRecoverTime", this.energyRecoverTime);
	}

	public int getStudySchedule() {
		return studySchedule;
	}

	public void putStudySchedule(int studySchedule) {
		if (this.studySchedule != studySchedule) {
			this.studySchedule = studySchedule;
			updateRedisHashField(getKey(), "studySchedule", this.studySchedule);
		}
	}

	public void addStudySchedule(int value) {
		this.studySchedule += value;
		updateRedisHashField(getKey(), "studySchedule", this.studySchedule);
	}

	public int getCareer() {
		return career;
	}

	public void putCareer(int career) {
		if (this.career != career) {
			this.career = career;
			updateRedisHashField(getKey(), "career", this.career);
		}
	}

	public void addCareer(int value) {
		this.career += value;
		updateRedisHashField(getKey(), "career", this.career);
	}

	public int getCareerAddition() {
		return careerAddition;
	}

	public void putCareerAddition(int careerAddition) {
		if (this.careerAddition != careerAddition) {
			this.careerAddition = careerAddition;
			updateRedisHashField(getKey(), "careerAddition", this.careerAddition);
		}
	}

	public void addCareerAddition(int value) {
		this.careerAddition += value;
		updateRedisHashField(getKey(), "careerAddition", this.careerAddition);
	}

	public int getPartner() {
		return partner;
	}

	public void putPartner(int partner) {
		if (this.partner != partner) {
			this.partner = partner;
			updateRedisHashField(getKey(), "partner", this.partner);
		}
	}

	public void addPartner(int value) {
		this.partner += value;
		updateRedisHashField(getKey(), "partner", this.partner);
	}

	public int getPartnerAddition() {
		return partnerAddition;
	}

	public void putPartnerAddition(int partnerAddition) {
		if (this.partnerAddition != partnerAddition) {
			this.partnerAddition = partnerAddition;
			updateRedisHashField(getKey(), "partnerAddition", this.partnerAddition);
		}
	}

	public void addPartnerAddition(int value) {
		this.partnerAddition += value;
		updateRedisHashField(getKey(), "partnerAddition", this.partnerAddition);
	}

	public int getSecretary() {
		return secretary;
	}

	public void putSecretary(int secretary) {
		if (this.secretary != secretary) {
			this.secretary = secretary;
			updateRedisHashField(getKey(), "secretary", this.secretary);
		}
	}

	public void addSecretary(int value) {
		this.secretary += value;
		updateRedisHashField(getKey(), "secretary", this.secretary);
	}

	public int getSecretaryAddition() {
		return secretaryAddition;
	}

	public void putSecretaryAddition(int secretaryAddition) {
		if (this.secretaryAddition != secretaryAddition) {
			this.secretaryAddition = secretaryAddition;
			updateRedisHashField(getKey(), "secretaryAddition", this.secretaryAddition);
		}
	}

	public void addSecretaryAddition(int value) {
		this.secretaryAddition += value;
		updateRedisHashField(getKey(), "secretaryAddition", this.secretaryAddition);
	}

	public byte getQuality() {
		return quality;
	}

	public void putQuality(byte quality) {
		if (this.quality != quality) {
			this.quality = quality;
			updateRedisHashField(getKey(), "quality", this.quality);
		}
	}

	public void addQuality(byte value) {
		this.quality += value;
		updateRedisHashField(getKey(), "quality", this.quality);
	}

	public byte getAppearance() {
		return appearance;
	}

	public void putAppearance(byte appearance) {
		if (this.appearance != appearance) {
			this.appearance = appearance;
			updateRedisHashField(getKey(), "appearance", this.appearance);
		}
	}

	public void addAppearance(byte value) {
		this.appearance += value;
		updateRedisHashField(getKey(), "appearance", this.appearance);
	}

	public byte getCharacterId() {
		return characterId;
	}

	public void putCharacterId(byte characterId) {
		if (this.characterId != characterId) {
			this.characterId = characterId;
			updateRedisHashField(getKey(), "characterId", this.characterId);
		}
	}

	public void addCharacterId(byte value) {
		this.characterId += value;
		updateRedisHashField(getKey(), "characterId", this.characterId);
	}

	public byte getIsTwins() {
		return isTwins;
	}

	public void putIsTwins(byte isTwins) {
		if (this.isTwins != isTwins) {
			this.isTwins = isTwins;
			updateRedisHashField(getKey(), "isTwins", this.isTwins);
		}
	}

	public void addIsTwins(byte value) {
		this.isTwins += value;
		updateRedisHashField(getKey(), "isTwins", this.isTwins);
	}

	public String getSisterName() {
		return sisterName;
	}

	public void putSisterName(String sisterName) {
		if (!this.sisterName.equals(sisterName)) {
			this.sisterName = sisterName;
			updateRedisHashField(getKey(), "sisterName", this.sisterName);
		}
	}

	public byte getSex() {
		return sex;
	}

	public void putSex(byte sex) {
		if (this.sex != sex) {
			this.sex = sex;
			updateRedisHashField(getKey(), "sex", this.sex);
		}
	}

	public void addSex(byte value) {
		this.sex += value;
		updateRedisHashField(getKey(), "sex", this.sex);
	}

	public byte getSisterSex() {
		return sisterSex;
	}

	public void putSisterSex(byte sisterSex) {
		if (this.sisterSex != sisterSex) {
			this.sisterSex = sisterSex;
			updateRedisHashField(getKey(), "sisterSex", this.sisterSex);
		}
	}

	public void addSisterSex(byte value) {
		this.sisterSex += value;
		updateRedisHashField(getKey(), "sisterSex", this.sisterSex);
	}

	public String getName() {
		return name;
	}

	public void putName(String name) {
		if (!this.name.equals(name)) {
			this.name = name;
			updateRedisHashField(getKey(), "name", this.name);
		}
	}

	public int getIsStudy() {
		return isStudy;
	}

	public void putIsStudy(int isStudy) {
		if (this.isStudy != isStudy) {
			this.isStudy = isStudy;
			updateRedisHashField(getKey(), "isStudy", this.isStudy);
		}
	}

	public void addIsStudy(int value) {
		this.isStudy += value;
		updateRedisHashField(getKey(), "isStudy", this.isStudy);
	}

	public long getAddition() {
		return addition;
	}

	public void putAddition(long addition) {
		if (this.addition != addition) {
			this.addition = addition;
			updateRedisHashField(getKey(), "addition", this.addition);
		}
	}

	public void addAddition(long value) {
		this.addition += value;
		updateRedisHashField(getKey(), "addition", this.addition);
	}

	public long getBaseConsume() {
		return baseConsume;
	}

	public void putBaseConsume(long baseConsume) {
		if (this.baseConsume != baseConsume) {
			this.baseConsume = baseConsume;
			updateRedisHashField(getKey(), "baseConsume", this.baseConsume);
		}
	}

	public void addBaseConsume(long value) {
		this.baseConsume += value;
		updateRedisHashField(getKey(), "baseConsume", this.baseConsume);
	}

}